package com.zhan.ielts.dao.impl;

import com.zhan.frame.core.dao.impl.BaseDaoImpl;
import com.zhan.frame.core.exception.DaoException;
import com.zhan.frame.core.utils.BeanUtils;
import com.zhan.ielts.dao.TopicDao;
import com.zhan.ielts.dao.TopicQADao;
import com.zhan.ielts.domain.Param;
import com.zhan.ielts.domain.Topic;
import com.zhan.ielts.domain.TopicQA;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class TopicQADaoImpl extends BaseDaoImpl<TopicQA> implements TopicQADao {
    @Override
    public void deleteByParas(TopicQA topicQA) {
        try {
            Map<String, Object> params = BeanUtils.toMap(topicQA);
            sqlSessionTemplate.delete(getSqlName("deleteByParas"), params);
        } catch (Exception e) {
            throw new DaoException(String.format("查询对象数量出错！语句：%s", getSqlName("deleteByParas")), e);
        }
    }

    @Override
    public List<TopicQA> selectParam(TopicQA query) {
        try {
            Map<String, Object> params = BeanUtils.toMap(query);
            return sqlSessionTemplate.selectList(getSqlName("selectParam"), params);
        } catch (Exception e) {
            throw new DaoException(String.format("查询对象数量出错！语句：%s", getSqlName("selectParam")), e);
        }
    }

    @Override
    public void insertBatch(List<TopicQA> list) {
        try {
            sqlSessionTemplate.insert(getSqlName("insertBatch"), list);
        } catch (Exception e) {
            throw new DaoException(String.format("查询对象数量出错！语句：%s", getSqlName("insertBatch")), e);
        }
    }

    @Override
    public void insertSelective(TopicQA qa) {
        try {
            sqlSessionTemplate.insert(getSqlName("insertSelective"), qa);
        } catch (Exception e) {
            throw new DaoException(String.format("查询对象数量出错！语句：%s", getSqlName("insertSelective")), e);
        }
    }

    @Override
    public void truncate() {
        try {
            sqlSessionTemplate.delete(getSqlName("truncate"), null);
        } catch (Exception e) {
            throw new DaoException(String.format("查询对象数量出错！语句：%s", getSqlName("truncate")), e);
        }
    }
}
